package com.globalresources.ui.struts.action.menu;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.globalresources.commons.AbstractAction;
import com.globalresources.business.inface.IGroupsService;
import java.util.List;
import com.globalresources.po.Groups;

public class GroupsAction extends AbstractAction implements ServletRequestAware{
	private HttpServletRequest request;
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}		
	private IGroupsService groupsService;	
	private List<Groups> listgroups;
	private Groups groups;	
	private String message;
	
	public String listGroups(){		
	listgroups=groupsService.listGroups();		
	return SUCCESS;
	}
	
	public String saveGroups(){		
		groupsService.saveGroups(groups);
		return SUCCESS;
	}
	
	public String editGroups(){		
		String id=request.getParameter("id");
		groups=groupsService.getGroupsById(id);
		return SUCCESS;
	}
	
	public String saveOrUpdateGroups(){		
		groupsService.saveOrUpdateGroups(groups);
		return SUCCESS;
	}
	
	public String deleteGroups(){
		try{
		String id=request.getParameter("id");
		groups=groupsService.getGroupsById(id);
		groupsService.deleteGroups(groups);
		setMessage("delete success, please continure your opertate");
		return SUCCESS;
		}catch(Exception e){e.printStackTrace();
		setMessage("delete ERROR,try again, or contact the System Administrator");
		return ERROR;
		}
	}


	/**
	 * @return the groupsService
	 */
	public IGroupsService getGroupsService() {
		return groupsService;
	}


	/**
	 * @param groupsService the groupsService to set
	 */
	public void setGroupsService(IGroupsService groupsService) {
		this.groupsService = groupsService;
	}


	/**
	 * @return the listgroups
	 */
	public List<Groups> getListgroups() {
		return listgroups;
	}


	/**
	 * @param listgroups the listgroups to set
	 */
	public void setListgroups(List<Groups> listgroups) {
		this.listgroups = listgroups;
	}


	/**
	 * @return the groups
	 */
	public Groups getGroups() {
		return groups;
	}


	/**
	 * @param groups the groups to set
	 */
	public void setGroups(Groups groups) {
		this.groups = groups;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}
	
	
	
	
	
	
	
}
